﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

// FROM ADO.Net
using System.Data.SqlClient;
using System.Data;

namespace yoADO
{
    public partial class Standard : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
          
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            String connectionString = "Data Source=localhost;Initial Catalog=Northwind;Persist Security Info=True;User ID=yoADO;Password=cs490;Asynchronous Processing=true";
            //String connectionString = "Data Source=web.ankitbuti.com;Initial Catalog=Northwind;Persist Security Info=True;User ID=yoADO;Password=cs490;Asynchronous Processing=true";
           
            SqlConnection connection = new SqlConnection(connectionString);

            String queryString = "SELECT [OrderID], [EmployeeID], [OrderDate], [CustomerID], [RequiredDate], [ShippedDate], [ShipAddress] FROM [Orders]";
            SqlCommand command = new SqlCommand(queryString, connection);

            SqlDataAdapter myDataAdapter = new SqlDataAdapter(command);

            DataSet myDataSet = new DataSet();
            myDataAdapter.Fill(myDataSet);

            DataTable myDataTable = myDataSet.Tables[0];

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("<table border=\"1\">");
            sb.Append("<tr><th>OrderID</th><th>EmployeeID</th><th>OrderDate</th><th>CustomerID</th><th>RequiredDate</th><th>ShippedDate</th><th>ShipAddress</th></tr>");

            foreach (DataRow dataRow in myDataTable.Rows)
            {
               sb.Append("<tr>");
               sb.Append("<td>" + dataRow["OrderID"].ToString() + "</td>");
               sb.Append("<td>" + dataRow["EmployeeID"].ToString() + "</td>");
               sb.Append("<td>" + dataRow["OrderDate"].ToString() + "</td>");
               sb.Append("<td>" + dataRow["CustomerID"].ToString() + "</td>");
               sb.Append("<td>" + dataRow["RequiredDate"].ToString() + "</td>");
               sb.Append("<td>" + dataRow["ShippedDate"].ToString() + "</td>");
               sb.Append("<td>" + dataRow["ShipAddress"].ToString() + "</td>");
               sb.Append("</tr>");
            }
            sb.Append("</table>");
            Literal1.Text = sb.ToString();
        }
    }
}